#------------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Bullet.py
# Purpose:     Bouncing Bullet Object
# 
# Authors:     Bailey Robinson, Calvin Berger, Alyissa Jackson
# Main Author: Bailey Robinson
#
# Created:     11/30/2012
# Copyright:   (c) Pineapple 2012
# Licence:     New BSD
#------------------------------------------------------------------------------
import pygame, math, sys, random

class Bullet():
    def __init__(self, speed, position, screenSize):
        self.surfaces = []
        for num in range(1, 2):
            surf = pygame.image.load("rsc/silvaa bullet.png")
            surf = pygame.transform.scale(surf, (100,70))
            self.surfaces += [surf]
        self.frame = 0
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.speed = speed
        self.speed
        self.place(position)
        self.living = True
        self.damage = 2
        if pygame.mixer:
            self.bounceSound = pygame.mixer.Sound("bounce.wav")
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.radius = self.rect.width/2 
       
    def  __str__(self):
        return "I'm a Bullet" + str(self.rect.center)
        
        
    def place(self, position):
        self.rect.center = position
        #print "I've moved to", position; 
        
        
    def move(self):
        self.rect = self.rect.move(self.speed)
        #print "I've moved", self.speed;
         
        
    def collideFloor(self, screenHeight):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.living = False
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.living = False
        #print "trying to hit bottom of screen", screenHeight;
        
        
    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.living = False
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.living = False
        #print "trying to hit edges of screen", screenWidth, screenHeight;
        
    def collideEnemy(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius): 
                        self.living = False
                        other.living = False
                        return True
                        
        #print "trying to hit Helicopter", str(helicopter);
        
    def collidePlayer(self, player):
        if (self.rect.right > player.rect.left 
            and self.rect.left < player.rect.right):
            if (self.rect.bottom > player.rect.top and 
                self.rect.top < player.rect.bottom):
                if (self.distToPoint(player.rect.center)
                    < self.radius + player.radius): 
                        self.living = False
                        return True
        return False
                        
    def collideBullet(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):  
                        self.living = False
                        other.living = False
        #print "trying to hit Helicopter", str(other);
        pass
        
    def bullet(self, enemy):
        #print "im a bullet";
        pass
        
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
        
    def God(self, other):
            self.living = False
            other.living = False
    
        
        #if pygame.mixer:
        #   self.helicopterSound.play()